﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.Data;
using System.Configuration;
using System.Data;

namespace blackhouse.Web.Requests {
	public class StoredRequest {

		#region Fields

		private MsSqlAdoDataHelper dataHelper;

		#endregion

		#region Constructors

		public StoredRequest() {
			this.dataHelper = new MsSqlAdoDataHelper(ConfigurationManager.AppSettings["MSSQLConnectionString"]);
		}

		#endregion

		#region Methods

		public int Add(string data) {
			this.dataHelper.Reset();
			this.dataHelper.ProcedureName = "bhp_StoredRequestAdd";
			this.dataHelper.AddParameter("RequestData", data, DbType.String);
			this.dataHelper.AddParameter("RequestHash", data.GetMd5(), DbType.String);
			return Convert.ToInt32(this.dataHelper.ExecuteScalar());

		}

		public string Get(int requestId) {
			this.dataHelper.Reset();
			this.dataHelper.ProcedureName = "bhp_StoredRequestGet";
			this.dataHelper.AddParameter("RequestId", requestId, DbType.Int32);
			return Convert.ToString(this.dataHelper.ExecuteScalar());

		}

		#endregion

	}
}